﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Security;
using System.Windows.Forms;

namespace MDIApplication
{
    public partial class Report : Form
    {

        string staffPosition;
        public Report(string staffPositionLogin)
        {
            staffPosition = staffPositionLogin;
            InitializeComponent();
        }

        private void Report_Load(object sender, EventArgs e)
        {
            if (staffPosition == "FirstLine")
            {
                btnrmocc.Visible = false;
                label2.Visible = false;
                btnhs.Visible = false;
            }
        }

        RoomStatusReport rs;
        private void btnrmstat_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (rs == null)
            {
                rs = new RoomStatusReport();
                rs.MdiParent = this.MdiParent;
                rs.Location = new Point(0, 0);
                rs.Show();
            }
        }
        GuestRoomReport gr;
        private void btnguestrm_Click(object sender, EventArgs e)
        {
            CloseAllForms();
            if (gr == null)
            {
                gr = new GuestRoomReport();
                gr.MdiParent = this.MdiParent;
                gr.Location = new Point(0, 0);
                gr.Show();
            }
        }

        AllRoomsReport ar;
        private void btnallrm_Click(object sender, EventArgs e)
        {         
            CloseAllForms();
            if (ar == null)
            {
                ar = new AllRoomsReport(); 
                ar.MdiParent = this.MdiParent;
                ar.Location = new Point(0, 0);
                ar.Show();
            }
        }
        HousekeepingSchedule hs;
        private void btnhs_Click(object sender, EventArgs e)
        {
 
                CloseAllForms();
                if (hs == null)
                {
                    hs = new HousekeepingSchedule();
                    hs.MdiParent = this.MdiParent;
                    hs.Location = new Point(0, 0);
                    hs.Show();
                }
            
        }

        //public void Application_AuthenticateRequest( Object src , EventArgs e )
        //{
        //    if (!(HttpContext.Current.User == null))
        //    {
        //        if (HttpContext.Current.User.Identity.AuthenticationType == "Forms")
        //        {
        //            System.Web.Security.FormsIdentity id;
        //            id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
        //            String[] myRoles = new String[2];
        //            myRoles[0] = "Management";
        //            myRoles[1] = "Administrator";
        //            HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id, myRoles);
        //        }
        //    }
        //}

        RoomOccupancyReport ro;
        private void btnrmocc_Click(object sender, EventArgs e)
        {         
            CloseAllForms();
            if (ro == null)
            {
               ro = new RoomOccupancyReport();
               ro.MdiParent = this.MdiParent;
               ro.Location = new Point(0, 0);
               ro.Show();
            }                
        }

        Report report;
        private void toolStripButton1_Click(object sender, EventArgs e)
        {  
            CloseAllForms();
            if (report == null)
            {
                report = new Report(staffPosition);
                report.MdiParent = this.MdiParent;
                report.Location = new Point(0, 0);
                report.Show();
            }
        
        }

        #region CloseAllForms
        private void CloseAllForms()
        {
            Form[] formToClose = null;
            int i = 1;
            foreach (Form form in Application.OpenForms)
            {
                if (form != this && form.IsMdiChild) //this is form1
                {
                    Array.Resize(ref formToClose, i);
                    formToClose[i - 1] = form;
                    i++;
                }
            }
            if (formToClose != null)
            {
                for (int j = 0; j < formToClose.Length; j++)
                {
                    formToClose[j].Close();
                }
                rs = null;
                hs = null;
                ro = null;
                ar =null;
                report = null;
            }
        }
        #endregion CloseAllForms


    }
}
